package com.xiaoshuidi.cloud.module.rooms.iotfegin;

import java.io.Serializable;

/**
 * Created by Arvin on 06/11/18.
 */
public class ResultModel<T> implements Serializable {
    private static final long serialVersionUID = 642651043174947736L;

    public static final String CODE_SUCCESS = "0";
    public static final String CODE_ERROR = "-1";

    private String code = CODE_SUCCESS;
    private T data;
    private String msg;
    private String traceId;

    private ResultModel() {
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public static <T extends Object> ResultModel<T> createSuccess() {
        ResultModel<T> result = new ResultModel<T>();
        result.setCode(CODE_SUCCESS);
//		result.setSuccess(true);
        //result.setTraceId(TraceIdHelper.getTraceId());
        return result;
    }


    public static <T extends Object> ResultModel<T> createSuccess(T data) {
        ResultModel<T> result = ResultModel.createSuccess();
        result.setData(data);
        return result;
    }

    /*public static <T extends Object> ResultModel<T> createProcess(String code) {
        return createProcess(code, ErrorCodeMap.getValueByCode(code));
    }*/

    public static <T extends Object> ResultModel<T> createProcess(String code, String msg) {
        ResultModel<T> result = new ResultModel<T>();
        result.setCode(code);
//		result.setSuccess(false);
        result.setMsg(msg);
        //result.setTraceId(TraceIdHelper.getTraceId());
        return result;
    }

   /* public static <T extends Object> ResultModel<T> createFail(String code) {
        return createFail(code, ErrorCodeMap.getValueByCode(code));
    }*/

    public static <T extends Object> ResultModel<T> createFail(String code, String msg) {
        ResultModel<T> result = new ResultModel<T>();
        result.setCode(code);
//		result.setSuccess(false);
        result.setMsg(msg);
        //result.setTraceId(TraceIdHelper.getTraceId());
        return result;
    }

    public static <T extends Object> ResultModel<T> createNativeFail(String msg) {
        ResultModel<T> result = new ResultModel<T>();
        result.setCode(CODE_ERROR);
        result.setMsg(msg);
        //result.setTraceId(TraceIdHelper.getTraceId());
        return result;
    }

    public String toDetailString(){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("ResultModel{").append("code = ").append(code).append(",data=").append(null == data ? "":data.toString())
                .append(",msg = ").append(msg).append(",traceId =").append(traceId).append("}");
        return stringBuilder.toString();
    }


}
